package com.lysb.modules.service;

import com.lysb.modules.entity.*;
import com.lysb.modules.mapper.BusinessMapper;
import com.lysb.modules.mapper.ILyDzBxgsMapper;
import com.lysb.modules.mapper.IZyBrryMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class BusinessService {
    @Resource
    private BusinessMapper mapper;
    @Resource
    private IZyBrryMapper zyBrryMapper;
    @Resource
    private ILyDzBxgsMapper lyDzBxgsMapper;

    /**
     * 门诊基本信息
     * @param treatmentRecordParam
     * @return
     */
    public List<TreatmentRecordData> treatmentRecord(TreatmentRecordParam treatmentRecordParam) {
        return mapper.treatmentRecord(treatmentRecordParam);
    }
    /**
     * 门诊收费明细
     * @param outpatientPrescriptionParam
     * @return
     */
    public List<OutpatientPrescriptionData> outpatientPrescription(OutpatientPrescriptionParam outpatientPrescriptionParam) {
        return mapper.outpatientPrescription(outpatientPrescriptionParam);
    }
    /**
     * 门诊费用结算
     * @param outpatientSettleParam
     * @return
     */
    public List<OutpatientSettleData> outpatientSettle(OutpatientSettleParam outpatientSettleParam) {
        return mapper.outpatientSettle(outpatientSettleParam);
    }
    /**
     * 门诊病历信息
     * @param outpatientInformationParam
     * @return
     */
    public List<OutpatientInformationData> outpatientInformation(OutpatientInformationParam outpatientInformationParam) {
        return mapper.outpatientInformation(outpatientInformationParam);
    }
    /**
     * 住院收费明细
     * @param hospitalizationPrescriptionParam
     * @return
     */
    public List<HospitalizationPrescriptionData> hospitalizationPrescription(HospitalizationPrescriptionParam hospitalizationPrescriptionParam) {
        return mapper.hospitalizationPrescription(hospitalizationPrescriptionParam);
    }
    /**
     * 住院费用结算
     * @param hospitalizationSettleParam
     * @return
     */
    public List<HospitalizationSettleData> hospitalizationSettle(HospitalizationSettleParam hospitalizationSettleParam) {
        return mapper.hospitalizationSettle(hospitalizationSettleParam);
    }
    /**
     * 住院基本信息
     * @param hospitalizationRecordParam
     * @return
     */
    public List<HospitalizationRecordData> hospitalizationRecord(HospitalizationRecordParam hospitalizationRecordParam) {
        return mapper.hospitalizationRecord(hospitalizationRecordParam);
    }

    /**
     * 住院入院记录
     * @param admissionRecordParam
     * @return
     */
    public List<AdmissionRecordData> admissionRecord(AdmissionRecordParam admissionRecordParam) {
        return mapper.admissionRecord(admissionRecordParam);
    }
    /**
     * 住院出院记录
     * @param dischargeRecordParam
     * @return
     */
    public List<DischargeRecordData> dischargeRecord(DischargeRecordParam dischargeRecordParam) {
        return mapper.dischargeRecord(dischargeRecordParam);
    }
    /**
     * 手术信息记录
     * @param surgicalRecordParam
     * @return
     */
    public List<SurgicalRecordData> surgicalRecord(SurgicalRecordParam surgicalRecordParam) {
        return mapper.surgicalRecord(surgicalRecordParam);
    }
    /**
     * 疾病信息记录
     * @param diagnosisRecordParam
     * @return
     */
    public List<DiagnosisRecordData> diagnosisRecord(DiagnosisRecordParam diagnosisRecordParam) {
        return mapper.diagnosisRecord(diagnosisRecordParam);
    }

    /**
     * 商保直赔身份确认通知
     * @param confirmUserParam
     * @return
     */
    public ConfirmUserData confirmUser(ConfirmUserParam confirmUserParam) {
        ZyBrry zyBrry = zyBrryMapper.selectById(confirmUserParam.getMedicalNum());
        if(Objects.isNull(zyBrry)) {
            return ConfirmUserData.failed("400300", "未查询到患者信息！");
        }
        if(!confirmUserParam.getName().equals(zyBrry.getBrxm())) {
            return ConfirmUserData.failed("0", "患者姓名不匹配！");
        }
        String zjhm = zyBrry.getSfzh();
        if(StringUtils.isBlank(zjhm) && StringUtils.isNotBlank(zyBrry.getZjhm())) {
            zjhm = zyBrry.getZjhm();
        }
        if(!zjhm.equals(confirmUserParam.getCredentialNum())) {
            return ConfirmUserData.failed("0", "证件号码不匹配！");
        }
        if(CollectionUtils.isEmpty(confirmUserParam.getInsurerList())) {
            return ConfirmUserData.failed("0", "未获取到任何保险公司！");
        }

        return null;
    }
}